//============================================================================
// Name        : 2_2_2_Linux.cpp
// Author      : Eric Chen
// Version     :
// Copyright   : Your copyright notice
// Description : selection sort in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int A[]={4,8,15,16,23,42};

void printArray(int array[],int size)
{
	if(size>0)
	{
		for(int i=0;i<size;i++)
			cout<<array[i]<<",";
		cout<<endl;
	}
	else
	{
		cout<<"Damn,give me a correct array please"<<endl;
	}



}
int main()
{
	int size=(sizeof(A)/sizeof(int));
	cout<<"Array before selection sort:"<<endl;
	printArray(A,size);
	for(int i=0;i<size-1;i++) //(n-1)
	{
		int key=A[i];//n-1
		//searches the smallest number at the array
		for(int j=i+1;j<size;j++)//(n-1)n/2-1
		{
			if(A[i]>A[j])//n(n-1)/2-1
			{
				A[i]=A[j];//n(n-1)/2-1
				A[j]=key;//n(n-1)/2-1
			}

		}
		//worst run time is a(n*n)+bn+c

	}
	cout<<"Array after selection sort:"<<endl;
	printArray(A,size);
	return 0;
}
